package hu.crs.demobank.session;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

public class SessionManager {

	public static HttpSession getNewSession() {
		HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
		if (!session.isNew()) {
			session.invalidate();
			session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
		}
		return session;
	}
	public static HttpSession getSession() {
		HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		return session;
	}
	
	public static void invalidateSession() {
		HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		session.invalidate();
	}
}
